package com.zhongxi.guoyuan.adapter.beautifulStoreOrder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.seller.BillData;

import java.util.List;

/**
 * Created by Administrator on 2016/12/20.
 */

public class BillAdapter extends BaseAdapter {

    private Context context;
    private List<BillData> list;

    public BillAdapter(Context context, List<BillData> data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_order_info, parent, false);
            holder.tvDate = (TextView) convertView.findViewById(R.id.tvTime);
            holder.tvOrderId = (TextView) convertView.findViewById(R.id.tvOrderId);
            holder.tvCash = (TextView) convertView.findViewById(R.id.tvCash);
            holder.tvReward = (TextView) convertView.findViewById(R.id.tvCoin);
            holder.linearBackground = (LinearLayout) convertView.findViewById(R.id.linearBackground);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvReward.setVisibility(View.VISIBLE);

        if(position%2==0){
            holder.linearBackground.setBackgroundColor(context.getResources().getColor(R.color.bg_box_one));
        }else{
            holder.linearBackground.setBackgroundColor(context.getResources().getColor(R.color.bg_box_two));
        }
        if(null!=list.get(position)&&!"".equals(list.get(position))){
            BillData data = list.get(position);
            if(null!=data.getCtime()&&!"".equals(data.getCtime())){
                holder.tvDate.setText(data.getCtime());
            }else{
                holder.tvDate.setText("");
            }
            if(null!=data.getId()&&!"".equals(data.getId())){
                holder.tvOrderId.setText(data.getId());
            }else{
                holder.tvOrderId.setText("");
            }
            if(null!=data.getPay()&&!"".equals(data.getPay())){
                holder.tvCash.setText(data.getPay()+" 元");
            }else{
                holder.tvCash.setText("0 元");
            }
            if(null!=data.getBacksilvernum()&&!"".equals(data.getBacksilvernum())){
                holder.tvReward.setText(data.getBacksilvernum()+" 银币");
            }else{
                holder.tvReward.setText("0 银币");
            }
        }

        return convertView;
    }
    class ViewHolder{
        private TextView tvDate;
        private TextView tvOrderId;
        private TextView tvCash;
        private TextView tvReward;
        private LinearLayout linearBackground;
    }
}
